package Pdf;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by donar on 17/11/20.
 */
public class PdfMerge {
    public static void main(String[] args) throws IOException, DocumentException {
        PdfReader pdfReader = new PdfReader("http://overseas-logistics.oss-cn-shanghai.aliyuncs.com/elec-bill/2a2d21ce30000.pdf");
        PdfReader pdfReader2 = new PdfReader("http://overseas-logistics.oss-cn-shanghai.aliyuncs.com/elec-bill/2a2e15deb8000.pdf");
        PdfReader pdfReader3 = new PdfReader("http://overseas-logistics.oss-cn-shanghai.aliyuncs.com/elec-bill/2a2d3754a4000.pdf");
        PdfReader pdfReader4 = new PdfReader("http://overseas-logistics.oss-cn-shanghai.aliyuncs.com/elec-bill/2a2e19a2a8000.pdf");
        Document document = new Document();
        PdfCopy copy = new PdfCopy(document, new FileOutputStream("result.pdf"));
        document.open();
        copy.addDocument(pdfReader);
        copy.addDocument(pdfReader2);
        copy.addDocument(pdfReader3);
        copy.addDocument(pdfReader4);
        document.close();
        pdfReader.close();
        pdfReader2.close();
        pdfReader3.close();
        pdfReader4.close();
    }
}
